package com.mszlu.blog.controller;

import com.mszlu.blog.service.ArticleService;
import com.mszlu.blog.vo.ArticleVo;
import com.mszlu.blog.vo.Result;
import com.mszlu.blog.vo.params.PageParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: 邹卓
 * @Data: 2021/10/24 22:57
 */
@RestController
@RequestMapping(value = "articles")
//@CrossOrigin("http://localhost:8080")
public class ArticleController {

    @Autowired
    private ArticleService articleService;

    /**
     * 文章首页列表
     *
     * @param pageParams
     */
    @PostMapping
    @CrossOrigin(origins = "*", maxAge = 3600)
    public Result listArticle(@RequestBody PageParams pageParams) {
        return articleService.listArticle(pageParams);
    }

    /**
     * 最热文章
     *
     * @return
     */
    @PostMapping("hot")
    @CrossOrigin(origins = "*", maxAge = 3600)
    public Result hotArticles() {
        int limit = 6;
        return articleService.hotArticle(limit);
    }

    /**
     * 最新文章
     *
     * @return
     */
    @PostMapping("new")
    @CrossOrigin(origins = "*", maxAge = 3600)
    public Result newArticles() {
        int limit = 6;
        return articleService.newArticles(limit);
    }

    /**
     * 文章列表展示
     *
     * @return
     */
    @PostMapping("listArchives")
    public Result listArchives() {
        return articleService.listArchives();
    }

    /**
     * 文章详情
     * @param id
     * @return
     */
    @PostMapping("view/{id}")
    public Result findArticleById(@PathVariable("id") Long id) {
        ArticleVo articleVo = articleService.findArticleById(id);
        return Result.success(articleVo);
    }
}




